define(['egis'], function (egis) {
    Window.deserializer = Window.deserializer || new egis.core.Deserializer();
    Window.container = Window.container || {};
    dsBridge.register('create_RestWRASService', function (sourceId, url,  authType, clientId, clientSecret,tokenUrl) {
        //var restHttp = Window.container[http];
        var restGeoService = new egis.ews.RestWRASService({
            url: url,
            //http: restHttp,
            deserializer: Window.deserializer,
            authType: authType,
            clientId: clientId,
            clientSecret: clientSecret,
            tokenUrl:tokenUrl
        });
        Window.container[sourceId] = restGeoService;
    })

    dsBridge.registerAsyn('RestWRASService_query', function (sourceId, layer, filter, responseCallback) {
        var restWGASService = Window.container[sourceId];
        filter = Window.deserializer.createJsInstance(JSON.parse(filter));
        restWGASService.query(layer, filter).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })

    dsBridge.registerAsyn('RestWRASService_statistic', function (sourceId, layer, filter, responseCallback) {
        var restWRASService = Window.container[sourceId];
        filter = Window.deserializer.createJsInstance(JSON.parse(filter));
        restWRASService.statistic(layer, filter).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })

    dsBridge.registerAsyn('RestWRASService_districtSearch', function (sourceId, layer, districtCode, responseCallback) {
        var restWRASService = Window.container[sourceId];
        restWRASService.districtSearch(layer, districtCode).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })


    dsBridge.registerAsyn('RestWRASService_districtStat', function (sourceId, layer, districtCode, responseCallback) {
        var restWRASService = Window.container[sourceId];
        restWRASService.districtStat(layer, districtCode).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })

    dsBridge.registerAsyn('RestWRASService_nearbySearch', function (sourceId, layer, geometry, radius, responseCallback) {
        var restWRASService = Window.container[sourceId];
        geometry = Window.deserializer.createJsInstance(JSON.parse(geometry));
        restWRASService.nearbySearch(layer, geometry, radius).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })

    dsBridge.registerAsyn('RestWRASService_nearbyStat', function (sourceId, layer, geometry, radius, responseCallback) {
        var restWRASService = Window.container[sourceId];
        geometry = Window.deserializer.createJsInstance(JSON.parse(geometry));
        restWRASService.nearbyStat(layer, geometry, radius).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })
    dsBridge.registerAsyn('RestWRASService_boundsSearch', function (sourceId, layer, geometry, responseCallback) {
        var restWRASService = Window.container[sourceId];
        geometry = Window.deserializer.createJsInstance(JSON.parse(geometry));
        restWRASService.boundsSearch(layer, geometry).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })
    dsBridge.registerAsyn('RestWRASService_boundsStat', function (sourceId, layer, geometry, responseCallback) {
        var restWRASService = Window.container[sourceId];
        geometry = Window.deserializer.createJsInstance(JSON.parse(geometry));
        restWRASService.boundsStat(layer, geometry).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })

})